﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VersionComparer.Base;
namespace VersionComparer.Views
{
    public class ScrollableWebBrowser : WebBrowser
    {
        const int WM_VSCROLL = 277;
        const int WM_MOUSEWHEEL = 0x020A;
        const int SB_THUMBTRACK = 5;
        

        public event EventHandler Scrolled;

        public int HorizontalScrollPos
        {
            get
            {
                return Document.Body.ScrollLeft;
            }
            set
            {
                Document.Body.ScrollLeft = value;
            }
        }
        public int VerticalScrollPos
        {
            get
            {
                return Document.Body.ScrollTop;
            }
            set
            {
                Document.Body.ScrollTop = value;
            }
        }

       

        public void DocScroll(object sender, EventArgs args)
        {
            Scrolled.Execute(this, args);
        }
        protected override void OnDocumentCompleted(WebBrowserDocumentCompletedEventArgs e)
        {
            if (!IsBusy && Url == e.Url && ReadyState == WebBrowserReadyState.Complete)
            {
                Document.Window.AttachEventHandler("onscroll", DocScroll);
            }

            base.OnDocumentCompleted(e);
        }
    }
}
